package com.sgb.auction.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sgb.auction.BR;
import com.sgb.auction.R;
import com.sgb.auction.entity.BiddingQueryListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * Time:2021/11/22
 * AUTHOR:F_Q
 * Description:
 */
public class BiddingQueryAdapter  extends BaseRecycleAdapter<BiddingQueryListEntity> {

    public BiddingQueryAdapter(Context context, List<BiddingQueryListEntity> datas) {
        super(context, R.layout.bidding_query_items, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        ImageView pmjmstate = holder.itemView.findViewById(R.id.pm_jm_state);
        TextView pmjmtime = holder.itemView.findViewById(R.id.pm_jm_time);
        TextView offer = holder.itemView.findViewById(R.id.offer);
        TextView auctionDetails = holder.itemView.findViewById(R.id.auction_details);
        TextView record = holder.itemView.findViewById(R.id.record);
        TextView tv_state = holder.itemView.findViewById(R.id.tv_state);
        LinearLayout ll_abortive_auction = holder.itemView.findViewById(R.id.ll_abortive_auction);
        //拍卖竞价状态（1、参拍中；2、已获拍；3、未获拍）
        switch (datas.get(position).getState()){
            case 1://参拍中
                pmjmstate.setImageResource(R.mipmap.pm_cpz);
                pmjmtime.setText("拍卖结束时间:"+datas.get(position).getAuctionEndTime()+"");
                //能否再次出价：0、不允许；1、允许
                if (datas.get(position).getAgain()==1){
                    offer.setVisibility(View.VISIBLE);
                }else {
                    offer.setVisibility(View.GONE);
                }
                break;
            case 2://已获拍
                pmjmstate.setImageResource(R.mipmap.pm_yhp);
                pmjmtime.setText("拍卖结束时间:"+datas.get(position).getAuctionEndTime()+"");
                offer.setVisibility(View.GONE);
                break;
            case 3://未获拍
                pmjmstate.setImageResource(R.mipmap.pm_whp);
                pmjmtime.setText("拍卖结束时间:"+datas.get(position).getAuctionEndTime()+"");
                offer.setVisibility(View.GONE);
                break;
        }
        //拍卖状态（0、草稿，1、待拍卖，2、拍卖中，3、拍卖结束4、流拍，5、撤拍）
        switch (datas.get(position).getAuctionState()){
            case "0":
                break;
            case "1":
                tv_state.setText("待拍卖");
                ll_abortive_auction.setVisibility(View.GONE);
                break;
            case "2":
                tv_state.setText("拍卖中");
                ll_abortive_auction.setVisibility(View.GONE);
                break;
            case "3":
                tv_state.setText("拍卖结束");
                ll_abortive_auction.setVisibility(View.GONE);
                break;
            case "4":
                tv_state.setText("流拍");
                ll_abortive_auction.setVisibility(View.VISIBLE);
                break;
            case "5":
                tv_state.setText("撤拍");
                ll_abortive_auction.setVisibility(View.GONE);
                break;
        }
        //再次出价
        offer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onitemprocessmode.onAuctionDetails(datas.get(position));
            }
        });
        //拍卖详情
        auctionDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onitemprocessmode.onAuctionDetails(datas.get(position));
            }
        });
        //竞买记录
        record.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onitemprocessmode.onBiddingRecord(datas.get(position));
            }
        });
    }

    private  onItemProcessMode  onitemprocessmode;

    public void setOnItemProcessMode(onItemProcessMode onItemProcessMode) {
        this.onitemprocessmode = onItemProcessMode;
    }
    public interface onItemProcessMode{

        void onAuctionDetails(BiddingQueryListEntity biddingQueryListEntity);

        void onBiddingRecord(BiddingQueryListEntity biddingQueryListEntity);
    }

    @Override
    public void convert(ItemViewHolder holder, BiddingQueryListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
    }
}
